<?php

class CasesView extends Cases{
	
	public function listar($arr){
		$total = count($arr);
		for($i = 0;$i < $total;$i++){
			echo '<tr>';
				echo '<td width="30%">',$arr[$i]['titulo'],'</td>';
				echo '<td width="20%" align="center" onclick="javascript:editar(',$arr[$i]['idcases'],',\'cases\');" class="tabelaB"><img src="images/app-edit-icon.png" width="20" align="absmiddle" /> Editar</td>';
				echo '<td width="20%" id="editar" align="center" onclick="javascript:excluir(',$arr[$i]['idcases'],',\'Cases\');" class="tabelaB"><img src="images/app-delete-icon.png" width="20" align="absmiddle" /> Excluir</td>';
			echo '</tr>';
	    }
	}
	public function select($arr){
		$total = count($arr);
		echo '<option value = "0">Selecione</option>';
		for($i = 0;$i < $total;$i++){
			echo '<option value="',$arr[$i]['idcases'],'">',$arr[$i]['titulo'],'</option>';
	    }
	}

	public function destaques($arr){
		$total = count($arr);
		for($i = 0;$i < $total;$i++){
			//echo '<a href="cases.php?i=',$arr[0]['idcases'],'" title="',$arr[0]['titulo'],'">';
			if($i+1 == $total){
				echo '<li id="',$arr[$i]['idcases'],'" rel="',$arr[$i]['titulo'],'" class="last" style="background:url(class/thumb.php?img=../imagens/cases/',$arr[$i]['imagem0'],'&w=450&h=450) no-repeat center;">';
			}else{
				echo '<li id="',$arr[$i]['idcases'],'" rel="',$arr[$i]['titulo'],'" style="background:url(class/thumb.php?img=../imagens/cases/',$arr[$i]['imagem0'],'&w=450&h=450) no-repeat center;">';
			}
			echo '<div class="cor_',$arr[$i]['idcategorias'],'_bg chamada_portfolio">',$arr[$i]['titulo'],'</div>';
			echo '</li>';
			//echo '</a>';
		}
	}
	public function selecionados($arr){
		$total = count($arr);
		$cor = array(1 => '1',2 => '2',3 => '3',4 => '4',5 => '5',6 => '6');
		for($i = 0;$i < $total;$i++){
			//echo '<a href="cases.php?i=',$arr[0]['idcases'],'" title="',$arr[0]['titulo'],'">';
				//if($i+1 == $total || $j == 4){
				if(1 == 2){
					echo '<li id="',$arr[$i]['idcases'],'" rel="',$arr[$i]['titulo'],'" class="last" style="background:url(class/thumb.php?img=../imagens/cases/',$arr[$i]['imagem0'],'&w=350&h=350) no-repeat center;">';
					$j = 0;
				}else{
					echo '<li id="',$arr[$i]['idcases'],'" rel="',$arr[$i]['titulo'],'" style="background:url(class/thumb.php?img=../imagens/cases/',$arr[$i]['imagem0'],'&w=450&h=450) no-repeat center;">';
				}
				echo '<div class="cor_',$cor[$arr[$i]['idcategorias']],'_bg linha_portfolio">&nbsp;</div>';
				echo '</li>';
			//echo '</a>';
		}
	}
	public function xml($arr,$parametros){		
		function searchForId($id, $array) {
			foreach ($array as $key => $val) {
				foreach ($array[$key] as $v) {
					if($v == $id){
						switch($key){
							case 'zon':
								return 1;
								break;
							case 'ind':
								return 2;
								break;
							case 'com':
								return 3;
								break;		
						}
					}
				}
			}
			return null;
		}
		
		$total = count($arr);
		$cor = array(1 => '1',2 => '3',3 => '5',4 => '2',5 => '4',6 => '6');
		$xml  = '<xml>';
		$xml .= '<cases>';
		for($i = 0;$i < $total;$i++){
			$id = searchForId($arr[$i]['idcases'], $parametros);
			$xml .= '<item id="'.$arr[$i]['idcases'].'" categoria="'.$arr[$i]['idcategorias'].'" flag="'.$id.'" >';			
				$xml .= '<categoria>'.$arr[$i]['nome_cat'].'</categoria>';
				$xml .= '<nome>'.$arr[$i]['nome_case'].'</nome>';
				$xml .= '<cor>'.$cor[$arr[$i]['idcategorias']].'</cor>';
				$xml .= '<frase>'.$arr[$i]['chamada'].'</frase>';
				$xml .= '<conteudo><![CDATA['.$arr[$i]['texto'].']]></conteudo>';
				
				$img = new Control('cases','imagens_cases',array(0 => $arr[$i]['idcases'], 1 => '4'));
				$img->Consult();
				$res = $img->result->lista;
				foreach($res as $img){
					$xml .= '<imagem url="'.$img['imagem0'].'" />';
				}
			$xml .= '</item>';
		}
		$xml .= '</cases>';
		$xml .= '</xml>';
		//escreve xml
		$arquivo = fopen('../list.xml','w+');
		fwrite($arquivo, $xml);
		fclose($arquivo);
		//download xml	
		header("Pragma: public");
		header("Expires: 0");
		header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
		header("Cache-Control: private",false);
		header("Content-Type: text/html");
		header("Content-Disposition: attachment; filename=\"".basename('../list.xml')."\";" );
		header("Content-Transfer-Encoding: binary");
		header("Content-Length: ".filesize('../list.xml'));
		readfile("../list.xml");
	}
	public function capa($arr){
		$total = count($arr);
		$cor = array(1 => '1',2 => '3',3 => '5',4 => '2',5 => '4',6 => '6');
		for($i = 0;$i < $total;$i++){
			echo '<a href="cases.php?i=',$arr[$i]['idcases'],'">';
				echo '<li>';
					echo '<img src="imagens/transparente.png" width="160" height="120" style="background:url(class/thumb.php?img=../imagens/cases/',$arr[$i]['imagem0'],'&w=250&h=250) no-repeat center;">';
					echo '<p><b>Case do mês:</b><br />';
					echo $arr[$i]['titulo'],'</p>';
				echo '</li>';
			echo '</a>';
		}
	}
}
?>